﻿// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_REP_CHECK_REPORT
// * CreateDate    : 2012-1-9 17:25:01
// * Creater       : CodeSmith
// * LastChangeDate: 2012-1-9 17:25:01
// * LastChanger   : 2012-1-9 17:25:01
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESOL.Common.Entity;
using Suzsoft.Smart.Data;
using System.Data;
using ESOL.Common;

namespace ESOL.Business.Rep
{
    /// <summary>
    /// RepCheckReport
    /// </summary>
    public partial class RepCheckReportBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objRepCheckReportEntity">Entity</param>
        /// <returns>Entity</returns>
        public static RepCheckReportEntity GetRepCheckReport(RepCheckReportEntity objRepCheckReportEntity)
        {
            return DataAccess.SelectSingle<RepCheckReportEntity>(objRepCheckReportEntity);
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objRepCheckReportEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertRepCheckReport(RepCheckReportEntity objRepCheckReportEntity)
        {
            return DataAccess.Insert(objRepCheckReportEntity);
        }

        public static bool InsertRepCheckReport(List<RepCheckReportEntity> objRepCheckReportEntityList)
        {
            return DataAccess.Insert(objRepCheckReportEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objRepCheckReportEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateRepCheckReport(RepCheckReportEntity objRepCheckReportEntity)
        {
            return DataAccess.Update(objRepCheckReportEntity);
        }

        public static bool UpdateRepCheckReport(List<RepCheckReportEntity> objRepCheckReportEntityList)
        {
            return DataAccess.Update<RepCheckReportEntity>(objRepCheckReportEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objRepCheckReportEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteRepCheckReport(RepCheckReportEntity objRepCheckReportEntity)
        {
            return DataAccess.Delete(objRepCheckReportEntity);
        }

        public static bool DeleteRepCheckReport(List<RepCheckReportEntity> objRepCheckReportEntityList)
        {
            return DataAccess.Delete<RepCheckReportEntity>(objRepCheckReportEntityList);
        }
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetRepCheckReportAll()
        {
            return DataAccess.SelectAllDataSet<RepCheckReportEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<RepCheckReportEntity> GetRepCheckReportAllList()
        {
            return DataAccess.SelectAll<RepCheckReportEntity>();
        }
        #endregion

        #region Functions
        public static bool SaveCheckReport(bool IsNew,RepCheckReportEntity Entity,DataTable Dt,List<RepCheckReportPicEntity> DeleteList)
        {
            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                try
                {
                    broker.BeginTransaction();
                    if (IsNew)
                    {
                        DataAccess.Insert(Entity, broker);
                    }
                    else
                    {
                        DataAccess.Update(Entity, broker);
                    }
                    List<RepCheckReportPicEntity> insertList = new List<RepCheckReportPicEntity>();
                    List<RepCheckReportPicEntity> modifyList = new List<RepCheckReportPicEntity>();
                    foreach (DataRow dr in Dt.Rows)
                    {
                        RepCheckReportPicEntity m = new RepCheckReportPicEntity(dr);
                        if (dr.RowState == DataRowState.Added)
                        {                            
                            insertList.Add(m);
                        }
                        if (dr.RowState == DataRowState.Modified)
                        {
                            modifyList.Add(m);
                        }
                    }
                    DataAccess.Delete<RepCheckReportPicEntity>(DeleteList, broker);
                    DataAccess.Update<RepCheckReportPicEntity>(modifyList, broker);
                    DataAccess.Insert<RepCheckReportPicEntity>(insertList, broker);
                    broker.Commit();
                    return true;
                }
                catch (Exception ex)
                {
                    broker.RollBack();
                    throw ex;
                }
            }
        }
        
        public static RepCheckReportEntity RepCheckReportByCheckInfoItemID(string CheckInfoItemID)
        {
            if (string.IsNullOrEmpty(CheckInfoItemID))
                return null;
            RepCheckReportEntity m=new RepCheckReportEntity();
            m.CheckInfoItemId = CheckInfoItemID;
            return DataAccess.SelectSingle<RepCheckReportEntity>(m);
        }
        #endregion
    }


}

